package com.chinasoftware.civilaviation.controller;

import com.chinasoftware.civilaviation.entity.Airport;
import com.chinasoftware.civilaviation.entity.EveryTwoHourAccount;
import com.chinasoftware.civilaviation.entity.StartPoint;
import com.chinasoftware.civilaviation.entity.TakeOffTime;
import com.chinasoftware.civilaviation.mapper.*;
import com.chinasoftware.civilaviation.service.StatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.springframework.web.bind.annotation.RequestMethod.POST;

@Controller
@RequestMapping(value = "/admin")
public class StatisticalController {

    @Autowired
    private StatisticalService statisticalService;

    @Autowired
    private PermonthflightincountMapper permonthflightincountMapper;

    @Autowired
    private PermonthflightoutcountMapper permonthflightoutcountMapper;

    @Autowired
    private TakeOffTimeMapper takeOffTimeMapper;

    @Autowired
    private StartPointMapper startPointMapper;

    @Autowired
    private DepartureTypeMapper departureTypeMapper;

    @Autowired
    private EveryTwoHourAccountMapper everyTwoHourAccountMapper;

    @Autowired
    private AirportMapper airportMapper;

    //Goods 范例
    @RequestMapping(value = "/getdata", method = POST)
    @ResponseBody
    public List<Map<String, Object>> getData() {
        System.out.println(statisticalService.groupByType());
        return statisticalService.groupByType();
    }

    @RequestMapping(value = "/getpermonthflightincount", method = POST)
    @ResponseBody
    public List<Map<String, Object>> getPerMonthFlightInCount() {
        return permonthflightincountMapper.selectHashmap();
    }

    @RequestMapping(value = "/getpermonthflightoutcount", method = POST)
    @ResponseBody
    public List<Map<String, Object>> getPerMonthFlightOutCount() {

        List<TakeOffTime> x = takeOffTimeMapper.getTakeOffTime();
        List<Integer> account = x.stream().map(TakeOffTime::getAccount).collect(Collectors.toList());
        List<String> fno = x.stream().map(TakeOffTime::getPid).collect(Collectors.toList());
        for (int i = 0; i < account.size(); i++) {
            System.out.println("[" + account.get(i) + "," + fno.get(i) + "]");
        }
        return permonthflightoutcountMapper.selectHashmap();
    }

    @RequestMapping(value = "/getTakeOffTime", method = POST)
    @ResponseBody
    public List<TakeOffTime> getTakeOffTime() {
        return takeOffTimeMapper.getTakeOffTime();
    }

    @RequestMapping(value = "/getStartPointAccount", method = POST)
    @ResponseBody
    public List<StartPoint> getStartPointAccount() {

        return startPointMapper.getStartPointAccount();
    }


    @RequestMapping(value = "/getDepartureFlightTypeAccount", method = POST)
    @ResponseBody
    public List<Integer> getDepartureFlightTypeAccount() {
        List list = new ArrayList();

        int a1 = departureTypeMapper.getDepartureFlightTypeAccount("PEK", "A330");
        int a2 = departureTypeMapper.getDepartureFlightTypeAccount("PEK", "A319");
        int a3 = departureTypeMapper.getDepartureFlightTypeAccount("PEK", "A321");
        int a4 = departureTypeMapper.getDepartureFlightTypeAccount("PEK", "B737");
        int a5 = departureTypeMapper.getDepartureFlightTypeAccount("PEK", "A320");
        int a6 = departureTypeMapper.getDepartureFlightTypeAccount("PEK", "其他");
        int b1 = departureTypeMapper.getDepartureFlightTypeAccount("CAN", "A330");
        int b2 = departureTypeMapper.getDepartureFlightTypeAccount("CAN", "A319");
        int b3 = departureTypeMapper.getDepartureFlightTypeAccount("CAN", "A321");
        int b4 = departureTypeMapper.getDepartureFlightTypeAccount("CAN", "B737");
        int b5 = departureTypeMapper.getDepartureFlightTypeAccount("CAN", "A320");
        int b6 = departureTypeMapper.getDepartureFlightTypeAccount("CAN", "其他");
        int c1 = departureTypeMapper.getDepartureFlightTypeAccount("SZX", "A330");
        int c2 = departureTypeMapper.getDepartureFlightTypeAccount("SZX", "A319");
        int c3 = departureTypeMapper.getDepartureFlightTypeAccount("SZX", "A321");
        int c4 = departureTypeMapper.getDepartureFlightTypeAccount("SZX", "B737");
        int c5 = departureTypeMapper.getDepartureFlightTypeAccount("SZX", "A320");
        int c6 = departureTypeMapper.getDepartureFlightTypeAccount("SZX", "其他");

        list.add(a1);
        list.add(a2);
        list.add(a3);
        list.add(a4);
        list.add(a5);
        list.add(a6);
        list.add(b1);
        list.add(b2);
        list.add(b3);
        list.add(b4);
        list.add(b5);
        list.add(b6);
        list.add(c1);
        list.add(c2);
        list.add(c3);
        list.add(c4);
        list.add(c5);
        list.add(c6);
        return list;
    }

    @RequestMapping(value = "/getPunctuality", method = POST)
    @ResponseBody
    public List<TakeOffTime> getPunctuality() {
        return takeOffTimeMapper.getPunctuality();
    }

    @RequestMapping(value = "/getEveryTwoHourAccount", method = POST)
    @ResponseBody
    public List<EveryTwoHourAccount> getEveryTwoHourAccount() {
        return everyTwoHourAccountMapper.getEveryTwoHourAccount();
    }

    @RequestMapping(value = "/getAirport", method = POST)
    @ResponseBody
    public List<Airport> getAirport() {
        return airportMapper.getAirport();
    }


//	@RequestMapping("/*")
//	public String toStatistical(HttpServletRequest request) {
//		String path = request.getServletPath();
//		System.out.println(path);
//		String requestPath = path.substring(path.indexOf("/")+1, path.indexOf("."));
//		System.out.println(requestPath);
//		return requestPath;
//	}

}
